package yangcheng;

import java.util.Scanner;

public abstract class Shape {
    String name;

    public Shape(String name) {
        this.name=name;
    }

    public abstract double calculateArea();

    public abstract double calculatePerimeter();

    public void displayInfo(){
        System.out.println("这个图形的名字是: "+name);
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
}


class Circle extends Shape {
    double radius;
    Scanner sc=new Scanner(System.in);
    public Circle(String name,double radius) {
        super(name);
        this.radius=radius;
    }

    public double getRadius() {
        return radius;
    }
    public void setRadius(double radius) {
        this.radius=radius;
    }

    @Override//重写
    public double calculateArea() {
        return radius*radius*Math.PI;
    }
    public double calculatePerimeter() {
        return 2*Math.PI*radius;
    }
    public void displayInfo(){
        super.displayInfo();
        System.out.println("这个圆的半径是"+radius);
    }
}


class Rectangle extends Shape {
    double length;
    double width;
    public Rectangle(String name,double length,double width) {
        super(name);
        this.width=width;
        this.length=length;
    }

    public void setWidth(double width) {
        this.width = width;
    }
    public void setLength(double length) {
        this.length = length;
    }
    public double getLength() {
        return length;
    }
    public double getWidth() {
        return width;
    }

    @Override
    public double calculateArea() {
        return length*width;
    }
    public double calculatePerimeter() {
        return 2*(length+width);
    }
    public void displayInfo(){
        super.displayInfo();
        System.out.println("这个长方形的长为："+length+"    "+"宽为："+width);
    }
}


class Triangle extends Shape{
    double side1;
    double side2;
    double side3;
    public Triangle(String name, double side1, double side2, double side3) {
        super(name);
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;
    }

    public boolean isRightTriangle() {
        return side1+side2>side3&&side3+side2>side1&&side1+side3>side2;
    }

    @Override
    public double calculateArea() {
        double a=(side1+side2+side3)/2;
        return Math.sqrt( a*(a-side1)*(a-side2)*(a-side3) );
    }
    public double calculatePerimeter() {
        return side1+side2+side3;
    }
    public void displayInfo(){
        super.displayInfo();
        System.out.println("这个三角形的三条边分别为："+side1+"  "+side2+"  "+side3);
    }
}


class Square extends Shape{
    double side;
    public Square(String name, double side) {
        super(name);
        this.side=side;
    }
    public double getSide() {
        return side;
    }

    @Override
    public double calculateArea() {
        return side*side;
    }
    public double calculatePerimeter() {
        return 4*side;
    }
    public void displayInfo(){
        super.displayInfo();
        System.out.println("这个正方形的边长为："+side);
    }
}
